TARGET  := benchmark_tsc
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc
PREFIX ?= /usr/local
BINDIR  = $(PREFIX)/bin
MANDIR  = $(PREFIX)/share/man
MAN1DIR = $(MANDIR)/man1
INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -p -m 755
INSTALL_DIR     = $(INSTALL) -p -m 755 -d
INSTALL_DATA    = $(INSTALL) -m 644
obj-m		:= benchmark_tsc.o

MODULE_OPTIONS = devices=2

${TARGET}.o: ${TARGET}.c

.PHONY: all install clean
.PHONY: install-all
.PHONY: modprobe benchmark_tsc

.PHONY: benchmark_tsc.ko

all: benchmark_tsc.ko
benchmark_tsc: benchmark_tsc.ko
benchmark_tsc.ko:
	@echo "Building benchmark_tsc driver..."
	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules

clean:
	rm -f *~

install-all: install
install:
	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules_install
	@echo ""
	@echo " SUCCESS"
	@echo ""

modprobe: benchmark_tsc.ko
	chmod a+r benchmark_tsc.ko
	-sudo rmmod benchmark_tsc
	sudo insmod ./benchmark_tsc.ko $(MODULE_OPTIONS)
